<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>手动实现promise:Bromise</title>
</head>
<body>
<script>
    function Bromise(executor) {
        var onResolve_ = null;
        var onReject_ = null;
        // 模拟实现 resolve 和 then，暂不支持 rejcet
        this.then = function (onResolve, onReject) {
            onResolve_ = onResolve;
        };
        function resolve(value) {
            setTimeout(() => {
                onResolve_(value);
            }, 100);
        }

        executor(resolve, null);
    }
    function executor(resolve, reject) {
        resolve(100)
    }
    // 将 Promise 改成我们自己的 Bromsie
    let p1 = new Bromise(executor)
    let p2 = p1.then((value) =>{
        console.log('success-1');
        return new Bromise(executor);
    });
    // let p3 = p2.then((value) =>{
    //     console.log('success-2');
    //     return new Bromise(executor);
    // });
    // p3.then((value) =>{
    //     console.log('success-3');
    //     return new Bromise(executor);
    // });
</script>
</body>
</html>
